package com.example.service

import org.zeromq.ZMQ
import kotlin.concurrent.thread


object JeroMqService {

    fun start() {
        //线程
        thread {
            val context = ZMQ.context(1) //I/O线程上下文的数量为1

            val socket = context.socket(ZMQ.REP) //ZMQ.REP表示这是一个reponse类型的socket

            socket.bind("tcp://*:8888") //绑定到8888端口

            while (true) {
                val request = socket.recv()
                println("服务端收到消息:\t" + String(request))
                val response = "I got it"
                socket.send(response.toByteArray())
            }
            //关闭
            socket.close()
            context.term()
        }
    }
}